package com.ruoyi.web.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.SuperNotice;
import com.ruoyi.system.service.ISuperNoticeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 公告Controller
 * 
 * @author ruoyi
 * @date 2025-08-13
 */
@RestController
@RequestMapping("/tool/notice")
public class SuperNoticeController extends BaseController
{
    @Autowired
    private ISuperNoticeService superNoticeService;

    /**
     * 查询公告列表
     */
    @PreAuthorize("@ss.hasPermi('tool:notice:list')")
    @GetMapping("/list")
    public TableDataInfo list(SuperNotice superNotice)
    {
        startPage();
        List<SuperNotice> list = superNoticeService.selectSuperNoticeList(superNotice);
        return getDataTable(list);
    }

    /**
     * 导出公告列表
     */
    @PreAuthorize("@ss.hasPermi('tool:notice:export')")
    @Log(title = "公告", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SuperNotice superNotice)
    {
        List<SuperNotice> list = superNoticeService.selectSuperNoticeList(superNotice);
        ExcelUtil<SuperNotice> util = new ExcelUtil<SuperNotice>(SuperNotice.class);
        util.exportExcel(response, list, "公告数据");
    }

    /**
     * 获取公告详细信息
     */
    @PreAuthorize("@ss.hasPermi('tool:notice:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(superNoticeService.selectSuperNoticeById(id));
    }

    /**
     * 新增公告
     */
    @PreAuthorize("@ss.hasPermi('tool:notice:add')")
    @Log(title = "公告", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SuperNotice superNotice)
    {
        return toAjax(superNoticeService.insertSuperNotice(superNotice));
    }

    /**
     * 修改公告
     */
    @PreAuthorize("@ss.hasPermi('tool:notice:edit')")
    @Log(title = "公告", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SuperNotice superNotice)
    {
        return toAjax(superNoticeService.updateSuperNotice(superNotice));
    }

    /**
     * 删除公告
     */
    @PreAuthorize("@ss.hasPermi('tool:notice:remove')")
    @Log(title = "公告", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(superNoticeService.deleteSuperNoticeByIds(ids));
    }
}
